function TreeNode(val) {
    this.val = val
    this.left = null
    this.right = null
}
var mirrorTree = function(root) {
    if (root == null) return root
    let left = root.left
    let right = root.right
    root.left = right
    root.right = left
    mirrorTree(root.left)
    mirrorTree(root.right)
    return root
}
var mirrorTree = function(root) {

    if (root == null) return root
    function mirror (root) {
        let left = root.left
        let right = root.right
        root.left = right
        root.right = left
    }
    mirror(root)
    mirrorTree(root.left)
    mirrorTree(root.right)
    return root
}
let root = new TreeNode(4)
root.left = new TreeNode(2)
root.right = new TreeNode(7)
root.left.left = new TreeNode(1)
root.left.right = new TreeNode(3)
root.right.left = new TreeNode(6)
root.right.right = new TreeNode(9)
console.log(mirrorTree(root))
